﻿using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;


namespace Helpers.Extensions
{
    public static class JsonHelperEx
    {
        public static string ToJsonString(this object obj)
        {
            return Helpers.JsonHelper.SerializeObject(obj);
        }

        public static T ToJsonObject<T>(this string json) where T : class
        {
            return Helpers.JsonHelper.Deserialize<T>(json);
        }

        public static T ToJsonObject<T>(this string json, ref T anonymousTypeObject) where T : class
        {
            return Helpers.JsonHelper.DeserializeAnonymousType<T>(json, ref anonymousTypeObject);
        }

        public static JToken AsJToken(this object @this)
        {
            return @this as JToken;
        }

        public static JArray AsJArray(this object @this)
        {
            return @this as JArray;
        }

        public static JObject AsJObject(this object @this)
        {
            return @this as JObject;
        }

        public static JProperty AsJProperty(this object @this)
        {
            return @this as JProperty;
        }
        public static JValue AsJValue(this object @this)
        {
            return @this as JValue;
        }
    }
}

